package com.mundus.world.renderbuffer;

import java.nio.IntBuffer;

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL30;

public class GBuffer {
	private int _width;
	private int _height;
	
	private FrameBuffer _fBuffer;
	public int _fbId;
	public int _diffuseId;
	public int _normalId;
	public int _depthId;
	
	public IntBuffer _drawBuffer;
	
	private RenderTarget _diffuseRT;
	private RenderTarget _normalRT;
	private RenderTarget _depthRT;
	
	public FrameBuffer getFrameBuffer(){ return _fBuffer;}	
	
	public GBuffer(int width, int height) throws LWJGLException{
		this._width = width;
		this._height = height;		
		initFrameBuffers();
	}
	
	private void initFrameBuffers() throws LWJGLException{						
		
		_diffuseRT = new RenderTarget(GL30.GL_RGBA32F, _width, _height, GL11.GL_RGBA, GL30.GL_COLOR_ATTACHMENT0);
		_normalRT = new RenderTarget(GL30.GL_RGBA32F, _width, _height, GL11.GL_RGBA, GL30.GL_COLOR_ATTACHMENT1);
		_depthRT = new RenderTarget(GL30.GL_DEPTH_COMPONENT32F, _width, _height, GL11.GL_DEPTH_COMPONENT, GL30.GL_DEPTH_ATTACHMENT);
		
		_fBuffer = new FrameBuffer();
		_fBuffer.addRenderTarget(_diffuseRT);
		_fBuffer.addRenderTarget(_normalRT);
		_fBuffer.addRenderTarget(_depthRT);
		
		_fBuffer.generateFrameBuffer();
	}
}
